import Vue from 'vue';

import Message from './message.vue';
let MessageConstructor = Vue.extend(Message);
class TheMessage{
    static dialog(options){
        let msg = typeof options === 'string' ? options : options.message;
        let type = typeof options === 'string' ? '' : options.type;
        if(!TheMessage.instance){
            TheMessage.instance = new MessageConstructor({
                el:document.createElement('div')
            })
            document.body.appendChild(TheMessage.instance.$el); 
        }
        if(TheMessage.instance.timer){
            clearTimeout(TheMessage.instance.timer)
        }

        TheMessage.instance.isShow = true;
        TheMessage.instance.type = type;
        TheMessage.instance.msg = msg;

        TheMessage.instance.timer = setTimeout(() => {
            TheMessage.instance.isShow = false;
        },3000)
        
        return TheMessage.instance
    }
}
export default TheMessage